﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.Revit;

namespace YArchitech.Plumbing
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class TextMarkCommand : HYExternalCommand
	{
		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		public override Result HYExecute(ref string TranName)
		{
			if (this.commandData == null)
			{
				throw new NotImplementedException();
			}
			Result result;
			try
			{
				TranName = "文字标注";
				base.UiApp.PostCommand(RevitCommandId.LookupPostableCommandId(Autodesk.Revit.UI.PostableCommand.Text));
				result = Autodesk.Revit.UI.Result.Succeeded;
			}
			catch (Exception ex)
			{
				this.message = ex.Message;
				result = Autodesk.Revit.UI.Result.Failed;
			}
			return result;
		}

		private void moveElement(List<DetailLine> DLines, XYZ dirVec, ref ElementSet groupSet)
		{
			foreach (DetailLine detailLine in DLines)
			{
				ElementTransformUtils.MoveElement(base.Doc, detailLine.Id, dirVec);
				groupSet.Insert(detailLine);
			}
		}

		private double getTextNoteWidth(TextNote tn)
		{
			double result;
			try
			{
				string[] array = tn.Text.Split(new char[]
				{
					'\n'
				});
				int num = 0;
				foreach (string s in array)
				{
					byte[] bytes = Encoding.Default.GetBytes(s);
					if (bytes.Length > num)
					{
						num = bytes.Length;
					}
				}
				Parameter parameter = tn.Symbol.GetParameter("文字大小");
				Parameter parameter2 = tn.Symbol.GetParameter("引线/边界偏移量");
				Parameter parameter3 = tn.Symbol.GetParameter("宽度系数");
				result = (0.5 * (double)num * parameter.AsDouble() * parameter3.AsDouble() * 1.15 + parameter2.AsDouble() * 2.0) * (double)base.Doc.ActiveView.Scale / 304.8;
			}
			catch (Exception ex)
			{
				YJKMessageBox.Show(ex.Message);
				result = 0.0;
			}
			return result;
		}

		public static YJKWindowHandle hWndRevit;
	}
}
